package cn.ibdsr.human.manager;

import cn.ibdsr.human.util.HttpClientUtils;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.entity.ContentType;
import org.springframework.stereotype.Component;


@Component
@Slf4j
public class UploadManager {

    public void uploadSetting(JSONObject bodyParams)
    {
        try {
            HttpResponse wxResponse = HttpClientUtils.obtainHttpsPostResponse("wljg.dct.jiangxi.gov.cn", 443,
                    "/upload-data/scenicReserveData/reserveInfo", null, bodyParams, ContentType.APPLICATION_JSON);
            // 检查http响应状态
            StatusLine statusLine = wxResponse.getStatusLine();
            if (statusLine.getStatusCode() != org.apache.http.HttpStatus.SC_OK) {
                log.error("请求失败：statusCode={}, reasonPhrase={}", statusLine.getStatusCode(), statusLine.getReasonPhrase());
                return;
            }
            else
            {
                log.error("请求成功：statusCode={}, reasonPhrase={}", statusLine.getStatusCode(), statusLine.getReasonPhrase());
            }

        } catch (Exception e) {
            log.error("发生异常", e);
            return;
        }
    }


    public void uploadStatistics(JSONArray bodyParams)
    {
        try {
            HttpResponse wxResponse = HttpClientUtils.obtainHttpsPostResponse("wljg.dct.jiangxi.gov.cn", 443,
                    "/upload-data/scenicReserveData/bookTravelerData", null, bodyParams, ContentType.APPLICATION_JSON);
            // 检查http响应状态
            StatusLine statusLine = wxResponse.getStatusLine();
            if (statusLine.getStatusCode() != org.apache.http.HttpStatus.SC_OK) {
                log.error("请求失败：statusCode={}, reasonPhrase={}", statusLine.getStatusCode(), statusLine.getReasonPhrase());
                return;
            }
            else
            {
                log.error("请求成功：statusCode={}, reasonPhrase={}", statusLine.getStatusCode(), statusLine.getReasonPhrase());
            }

        } catch (Exception e) {
            log.error("发生异常", e);
            return;
        }
    }

    public static void main(String[] args) {
    }

}
